package action.custom;

import java.util.List;

import core.action.BaseAction;
import core.global.Global;
import exception.Exceptions;
import model.company.*;
import service.custom.CustomLcBankInforService;
import service.custom.CustomServiceDo;
import util.Time;

public class CustomActionDo extends BaseAction{
	private CustomServiceDo customServiceDo;
	
	private Integer did;
	private Integer typecustom;
	
	private Companypledger companypledger;//抵质押清单	
	private Companyforeigninvestment cforeigninvestor;
	private Companygivingcredit  cgivingcredit;
	private Companyguarantor cguarantor;
	private Companyinvestor cinvestor;
	private Companylisting clisting;
	private Companyprosecuted cprosecuted;
	private Companytopmanager ctopmanager;
	private Companybasic cbasic;
	private Companycontact ccontact;
	private Companymanage cmanage;
	private Companybankcredit cbankcredit;
	private Companyexternalguarantee cexternalguarantee;
	private Companyassetsdebt cassetsdebt;
	private Companycashflow ccashflow;
	private Companyprofit cprofit;
	private Companyotherloan cotherloan;
	
	
	public Companyotherloan getCotherloan() {
		return cotherloan;
	}

	public void setCotherloan(Companyotherloan cotherloan) {
		this.cotherloan = cotherloan;
	}

	public Companyprofit getCprofit() {
		return cprofit;
	}

	public void setCprofit(Companyprofit cprofit) {
		this.cprofit = cprofit;
	}

	public Companycashflow getCcashflow() {
		return ccashflow;
	}

	public void setCcashflow(Companycashflow ccashflow) {
		this.ccashflow = ccashflow;
	}

	public Companyassetsdebt getCassetsdebt() {
		return cassetsdebt;
	}

	public void setCassetsdebt(Companyassetsdebt cassetsdebt) {
		this.cassetsdebt = cassetsdebt;
	}

	private List<String> basicbank;
	private List<String> basicdepositbank;
	
	private CustomLcBankInforService customLcBankInforService;
	
	public Companybankcredit getCbankcredit() {
		return cbankcredit;
	}

	public void setCbankcredit(Companybankcredit cbankcredit) {
		this.cbankcredit = cbankcredit;
	}


	
	public String execute() {
		return "success";
	}
	
	public String managedelete(){
		cmanage=customServiceDo.manageShow(did);
		customServiceDo.manageDelete(cmanage);
		MessageJump("删除成功","customList!managelist");
		return "message";
	}
	
	public String contactdelete(){
		ccontact=customServiceDo.contactShow(did);
		customServiceDo.contactDelete(ccontact);
		MessageJump("删除成功","customList!contactlist");
		return "message";
	}
	public String externalguaranteedelete(){
		cexternalguarantee=customServiceDo.externalguaranteeShow(did);
		customServiceDo.externalguaranteeDelete(cexternalguarantee);
		MessageJump("删除成功","customList!externalguaranteelist");
		return "message";
	}
	
	public String externalguaranteesave(){
		if( cexternalguarantee.getCid().equals("")){
			MessageJump("错误：客户id为空","BACK");
		}
		else{
			customServiceDo.externalguaranteeSave(cexternalguarantee);
			MessageJump("保存成功","customList!externalguaranteelist");
		}
		return "message";
	}
	
	public String otherloansave() throws Exceptions{
		if(cotherloan.getCid() == null){
			MessageJump("请选择客户","BACK");
		}
		customServiceDo.otherloanSave(cotherloan);
		MessageJump("保存成功","customList!otherloanlist");
		return "message";
	}
	
	public String managesave() throws Exceptions{
		if(cmanage.getCid() == null ){
		     MessageJump("请填写ID","BACK");
		}
		else{
			customServiceDo.manageSave(cmanage);
			//	System.out.println(cmanage.getId());
			customLcBankInforService.delete(cmanage.getCid(), cmanage.getId(), 2);
			customLcBankInforService.save(cmanage.getCid(), cmanage.getId(),  basicbank, basicdepositbank, 2);
			MessageJump("保存成功","customList!managelist");
		}
		return "message";
	}
	
	public String companydelete(){
		cbasic=customServiceDo.companyShow(did);
		customServiceDo.companyDelete(cbasic);
		MessageJump("删除成功","customList!companylist");
		return "message";
	}
	
	public String companysave(){
		if(cbasic.getId() == null ){
		     MessageJump("请填写用户id","BACK");
		}
		else{
			//cbasic.setOperatorcreatedate(Time.CurrentTimestamp());
			cbasic.setOperatordate(Time.CurrentTimestamp());
			cbasic.setOperatorid(Global.userid());
			String str=customServiceDo.companySave(cbasic);
			if(str.equals("TRUE")){
				MessageJump("保存成功","customShow!companyread");
			}else{
				MessageJump(str,"BACK");
			}			
		}
		return "message";
	}
	
	public String companyupdate(){
		if(cbasic.getOrganizationcode().equals("")){
			MessageJump("请填写组织机构代码","BACK");
		}else{
			//cbasic.setOperatorcreatedate(Time.CurrentTimestamp());
			cbasic.setOperatordate(Time.CurrentTimestamp());
			cbasic.setOperatorid(Global.userid());
			customServiceDo.companyUpdate(cbasic);
			MessageJump("保存成功","customShow!companyread");
		}
		return "message";
	}
	
	public String bankcreditsave(){
		if(cbankcredit.getCid().equals("")){
			MessageJump("错误：客户id为空","BACK");
		}
		customServiceDo.bankcreditSave(cbankcredit);
		MessageJump("保存成功","customList!bankcreditlist");			
		return "message";
	}
	
	public String bankcreditdelete(){
		cbankcredit =customServiceDo.bankcreditShow(did);
		customServiceDo.bankcreditDelete(cbankcredit);
		MessageJump("删除成功","customList!bankcreditlist");
		return "message";
	}
	
	
	public String cashflowsave(){
		if(ccashflow.getCid().equals("")){
			MessageJump("错误：客户id为空","BACK");
		}
		customServiceDo.cashflowSave(ccashflow);
		MessageJump("保存成功","customList!cashflowlist");
		return "message";
	}
	
	
	
	public String profitsave(){
		if(cprofit.getCid().equals("")){
			MessageJump("错误：客户id为空","BACK");
		}
		
		customServiceDo.profitSave(cprofit);
		MessageJump("保存成功","customList!profitlist");
		
		return "message";
	}
	
	
	public String assetsdebtsave(){
		if(cassetsdebt.getCid().equals("")){
			MessageJump("错误：客户id为空","BACK");
		}
		
		customServiceDo.assetsdebtSave(cassetsdebt);
		MessageJump("保存成功","customList!assetsdebtlist");
		
		return "message";
	}
	
	public String cashflowdelete(){
		ccashflow=customServiceDo.cashflowShow(did);
		customServiceDo.cashflowDelete(ccashflow);
		MessageJump("删除成功","customList!cashflowlist");
		return "message";
	}
	
	public String otherloandelete(){
		cotherloan=customServiceDo.otherloanShow(did);
		customServiceDo.otherloanDelete(cotherloan);
		MessageJump("删除成功","customList!otherloanlist");
		return "message";
	}
	
	public String profitdelete(){
		cprofit=customServiceDo.profitShow(did);
		customServiceDo.profitDelete(cprofit);
		MessageJump("删除成功","customList!profitlist");
		return "message";
	}
	
	public String assetsdebtdelete(){
		cassetsdebt=customServiceDo.assetsdebtShow(did);
		customServiceDo.assetsdebtDelete(cassetsdebt);
		MessageJump("删除成功","customList!assetsdebtlist");
		return "message";
	}
	
	public String contactsave(){
		
		customServiceDo.contactSave(ccontact);
		MessageJump("保存成功","customList!contactlist");	
			
		return "message";
	}
	
	
	public String pledgerdelete(){
		companypledger=customServiceDo.pledgerShow(did);
		customServiceDo.pledgerDelete(companypledger);
		if(typecustom == 2)
			MessageJump("删除成功","customList!pledgercompanylist");
		else
			MessageJump("删除成功","customList!pledgerpersonallist");
		return "message";
	}
	
	
	public String pledgersave(){
		if(companypledger.getCid().equals("")){
			MessageJump("错误：客户id为空","BACK");
		}else{
			customServiceDo.pledgerSave(companypledger);
			if(companypledger.getTypecustom() == 2)
				MessageJump("保存成功","customList!pledgercompanylist");
			else 
				MessageJump("保存成功","customList!pledgerpersonallist");	
		}		
		return "message";
	}
	
	public String foreigninvestordelete(){
		cforeigninvestor=customServiceDo.foreigninvestorShow(did);
		customServiceDo.foreigninvestorDelete(cforeigninvestor);
		MessageJump("删除成功","customList!foreigninvestorlist");
		return "message";
	}
	
	
	public String foreigninvestorsave(){
		int flage = 0;
		if( cforeigninvestor.getCid().equals("")){
			MessageJump("错误：客户id为空","BACK");
			flage = 1;
		}
		if(flage == 0){
			customServiceDo.foreigninvestorSave(cforeigninvestor);
			MessageJump("保存成功","customList!foreigninvestorlist");
		}
		return "message";
	}
	
	public String givingcreditsave(){
		if( cgivingcredit.getCid().equals("")){
			MessageJump("错误：客户id为空","BACK");
		}else{
			customServiceDo.givingcreditSave(cgivingcredit);
			MessageJump("保存成功","customList!givingcreditlist");
		}
		return "message";
	}
	
	public String guarantorsave(){
		if( cguarantor.getCid().equals("")){
			MessageJump("错误：客户id为空","BACK");
		}else{
			customServiceDo.guarantorSave(cguarantor);
			MessageJump("保存成功","customList!guarantorlist");
		}
		return "message";
	}
	
	public String investordelete(){
		cinvestor=customServiceDo.investorShow(did);
		customServiceDo.investorDelete(cinvestor);
		
		List<Companyinvestor> inlist = (List<Companyinvestor>)customServiceDo.investorList(cinvestor.getCid());
		double sum = 0;
		if(inlist != null){
		for(int i = 0;i < inlist.size();i++){
				sum += inlist.get(i).getAmount();
		}
		
		for(int i = 0;i < inlist.size();i++){
			inlist.get(i).setHoldshares(inlist.get(i).getAmount()*100/sum);
			customServiceDo.investorSave(inlist.get(i));
		}
		
		}
		
		MessageJump("删除成功","customList!investorlist");
		return "message";
	}
	
	public String investorsave(){
		int flage = 0;
		if( cinvestor.getCid().equals("")){
			MessageJump("错误：客户id为空","BACK");
			flage = 1;
		}
		
		if(flage == 0){
		    
			customServiceDo.investorSave(cinvestor);
			List<Companyinvestor> inlist = (List<Companyinvestor>)customServiceDo.investorList(cinvestor.getCid());
			double sum = 0;
			if(inlist != null){
			for(int i = 0;i < inlist.size();i++){
					sum += inlist.get(i).getAmount();
			}
			
			for(int i = 0;i < inlist.size();i++){
				inlist.get(i).setHoldshares(inlist.get(i).getAmount()*100/sum);
				customServiceDo.investorSave(inlist.get(i));
			}
			
			}
			MessageJump("保存成功","customList!investorlist");
		}
		return "message";
	}
	
	public String listingsave(){
		if( clisting.getCid().equals("")){
			MessageJump("错误：请先选择客户","BACK");
		}else{
			customServiceDo.listingSave(clisting);
			MessageJump("保存成功","customList!listinglist");
		}
		return "message";
	}
	
	
	public String prosecuteddelete(){
		cprosecuted=customServiceDo.prosecutedShow(did);
		customServiceDo.prosecutedDelete(cprosecuted);
		MessageJump("删除成功","customList!prosecutedlist");
		return "message";
	}
	
	
	public String prosecutedsave(){
		int flage = 0;
		
		if( cprosecuted.getCid().equals("")){
			MessageJump("错误：客户id为空","BACK");
			flage = 1;
		}
	
		if(flage == 0){
			customServiceDo.prosecutedSave(cprosecuted);
			MessageJump("保存成功","customList!prosecutedlist");
		}
		return "message";
	}
	
	public String topmanagerdelete(){
		ctopmanager=customServiceDo.topmanagerShow(did);
		customServiceDo.topmanagerDelete(ctopmanager);
		MessageJump("删除成功","customList!topmanagerlist");
		return "message";
	}
	
	
	public String topmanagersave(){
		int flage = 0;
		if( ctopmanager.getCid().equals("")){
			MessageJump("错误：请先选择客户","BACK");
			flage = 1;
		}
		
		if(flage == 1){
			return "message";
		}
		else{
			
			customServiceDo.topmanagerSave(ctopmanager);
			MessageJump("保存成功","customList!topmanagerlist");
		}
		return "message";
	}
	
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	public CustomServiceDo getCustomServiceDo() {
		return customServiceDo;
	}


	public void setCustomServiceDo(CustomServiceDo customServiceDo) {
		this.customServiceDo = customServiceDo;
	}

	public Companypledger getCompanypledger() {
		return companypledger;
	}

	public void setCompanypledger(Companypledger companypledger) {
		this.companypledger = companypledger;
	}

	public Companyforeigninvestment getCforeigninvestor() {
		return cforeigninvestor;
	}

	public void setCforeigninvestor(Companyforeigninvestment cforeigninvestor) {
		this.cforeigninvestor = cforeigninvestor;
	}

	public Companygivingcredit getCgivingcredit() {
		return cgivingcredit;
	}

	public void setCgivingcredit(Companygivingcredit cgivingcredit) {
		this.cgivingcredit = cgivingcredit;
	}

	public Companyguarantor getCguarantor() {
		return cguarantor;
	}

	public void setCguarantor(Companyguarantor cguarantor) {
		this.cguarantor = cguarantor;
	}

	public Companyprosecuted getCprosecuted() {
		return cprosecuted;
	}

	public void setCprosecuted(Companyprosecuted cprosecuted) {
		this.cprosecuted = cprosecuted;
	}

	public Companyinvestor getCinvestor() {
		return cinvestor;
	}

	public void setCinvestor(Companyinvestor cinvestor) {
		this.cinvestor = cinvestor;
	}

	public Companylisting getClisting() {
		return clisting;
	}

	public void setClisting(Companylisting clisting) {
		this.clisting = clisting;
	}

	public Companytopmanager getCtopmanager() {
		return ctopmanager;
	}

	public void setCtopmanager(Companytopmanager ctopmanager) {
		this.ctopmanager = ctopmanager;
	}

	public Companybasic getCbasic() {
		return cbasic;
	}

	public void setCbasic(Companybasic cbasic) {
		this.cbasic = cbasic;
		System.out.println("inhere");
	}

	public Companycontact getCcontact() {
		return ccontact;
	}

	public void setCcontact(Companycontact ccontact) {
		this.ccontact = ccontact;
	}

	public Companymanage getCmanage() {
		return cmanage;
	}

	public void setCmanage(Companymanage cmanage) {
		this.cmanage = cmanage;
	}

	public Companyexternalguarantee getCexternalguarantee() {
		return cexternalguarantee;
	}

	public void setCexternalguarantee(Companyexternalguarantee cexternalguarantee) {
		this.cexternalguarantee = cexternalguarantee;
	}

	public Integer getDid() {
		return did;
	}

	public void setDid(Integer did) {
		this.did = did;
	}

	public Integer getTypecustom() {
		return typecustom;
	}

	public void setTypecustom(Integer typecustom) {
		this.typecustom = typecustom;
	}

	public List<String> getBasicbank() {
		return basicbank;
	}

	public void setBasicbank(List<String> basicbank) {
		this.basicbank = basicbank;
	}

	public List<String> getBasicdepositbank() {
		return basicdepositbank;
	}

	public void setBasicdepositbank(List<String> basicdepositbank) {
		this.basicdepositbank = basicdepositbank;
	}

	public CustomLcBankInforService getCustomLcBankInforService() {
		return customLcBankInforService;
	}

	public void setCustomLcBankInforService(
			CustomLcBankInforService customLcBankInforService) {
		this.customLcBankInforService = customLcBankInforService;
	}
}
